#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstdio>
using namespace std;
int caidan[8] = { 0,7,27,41,49,63,78,108 };
int main()
{
	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		scanf("%d", &n);
		int sum = 0;
		for (int i = 0; i < n; i++) {
			int a;
			scanf("%d", &a);
			sum += caidan[a];
		}
		if (sum >= 120) {
			sum -= 50;
		}
		else if (sum >= 89) {
			sum -= 30;
		}
		else if (sum >= 69) {
			sum -= 15;
		}
		cout << sum << endl;
	}
	return 0;
}